package com.vencent.spring.bean;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.BeanFactoryAware;
import org.springframework.beans.factory.BeanNameAware;
import org.springframework.beans.factory.DisposableBean;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;

/**
 * POJO
 * @author 1d
 *
 */
public class Person implements BeanNameAware, BeanFactoryAware, ApplicationContextAware, InitializingBean, DisposableBean{

	public Person(){
		System.out.println("----bean级接口----");
		System.out.println("Person类构造方法，实例化一个对象");
	}
	private Long id;
	
	private String name;
	
	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		System.out.println("----bean级接口----");
		System.out.println("【注入属性】注入属性Id");
		this.id = id;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		System.out.println("----bean级接口----");
		System.out.println("【注入属性】注入属性name");
		this.name = name;
	}

	@Override
	public void destroy() throws Exception {
		// TODO Auto-generated method stub
		System.out.println("----bean级接口----");
		System.out.println("实现DisposableBean接口的destroy方法");
	}

	@Override
	public void afterPropertiesSet() throws Exception {
		// TODO Auto-generated method stub
		System.out.println("----bean级接口----");
		System.out.println("实现InitializingBean接口的afterPropertiesSet方法");
	}

	@Override
	public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
		// TODO Auto-generated method stub
		System.out.println("----bean级接口----");
		System.out.println("实现BeanFactoryAware接口的setBeanFactory方法");
	}

	@Override
	public void setBeanName(String name) {
		// TODO Auto-generated method stub
		System.out.println("----bean级接口----");
		System.out.println("实现BeanNameAware接口的setBeanName方法");
	}
	
	public void myInit(){
		System.out.println("----bean级接口----");
		System.out.println("自定义初始化方法， myInit()");
	}
	
	public void myDestroy(){
		System.out.println("----bean级接口----");
		System.out.println("自定义销毁方法， myDestroy()");
	}
	
	public String getBestOne(){
		System.out.println("----bean级接口----");
		System.out.println("获得最好的一个人, getBestOne()");
		return "VENCENT";
	}

	@Override
	public String toString() {
		return "Person [id=" + id + ", name=" + name + "]";
	}

	@Override
	public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
		// TODO Auto-generated method stub
		System.out.println("----bean级接口----");
		System.out.println("实现ApplicationContextAware接口的setApplicationContext方法");
	}
	
}
